<template>
  <div id="app">
    <!-- <m-header></m-header> -->
    <div class="wrapContant">
      <!-- <router-view></router-view> -->
      <router-view v-wechat-title='$route.meta.title'></router-view>
      <!-- <lg-preview></lg-preview> -->
    </div>
  </div>
</template> 

<script>
import ApiService from "@/services/API-servies";
import MHeader from "components/m-header/m-header";
import { mapActions } from "vuex";

export default {
  data() {
    return {
      loadList: [],
      selected: "",
      session: "",
      sessionId: "",
      timeTit: "",
      bidTime: "",
      bidTimeList: [],
      msg: "bidding",
      andrRes: "",
      iosSession: "",
      iosRes: "",
      userType: ""
    };
  },
  created: function() {
    // this.setSession();
    window.getUserInfo = this.getUserInfo;
    window.setUserInfo = this.setUserInfo;
  },
  mounted() {
    // setTimeout(() => {
    if (this.$isBrower.isAndroid) {
      this.getUserInfo();
    } else if (this.$isBrower.isIos) {
      this.getUserInfoIos();
    }
    // }, 0);
    // localStorage.setItem('userType',this.userType)//浏览器测试
  },
  methods: {
    ...mapActions(["setUserType"]),
    getUserInfo() {
      if (app.getUserInfo) {
        app.getUserInfo();
      }
    },
    setUserInfo(res) {
      this.andrRes = res;
      this.sessionId = res.sessionId;
      this.userType = res.userType;
      localStorage.setItem("userType", this.userType);
      this.setUserType(this.userType);
      this.setSession();
    },
    getUserInfoIos() {
      this.$bridge.registerhandler("JSEcho", (data, responseCallback) => {
        this.sessionId = data.sessionId;
        this.userType = data.userType;
        localStorage.setItem("userType", this.userType);
        this.setUserType(this.userType);
        this.setSession();
      });
    },
    setSession() {
      ApiService.session
        .setSession({
          sessionId: this.sessionId
        })
        .then(res => {
          if(res.meta.retCode != '0'){
              return ;
          }
          if(res.data.type == '20'){
            this.$router.push({path: '/audit'})
          }
          if(res.data.type == '30'){
            this.$router.push({path: '/reject'})
          }
          if(res.data.type == '50'){
            this.$router.push({path: '/hangup'})
          }
        });
    }
  },
  components: {
    MHeader
  }
};
</script>
<style lang="less" rel="stylesheet/less">
html,
body,
#app,
.wrapContant {
  height: 100%;
}
</style>
